package com.lxw.manage_cms.controller;

import com.lxw.api.cms.CmsTemplateControllerApi;
import com.lxw.framework.domain.cms.CmsTemplate;
import com.lxw.framework.model.response.CommonCode;
import com.lxw.framework.model.response.QueryResponseResult;
import com.lxw.framework.model.response.QueryResult;
import com.lxw.manage_cms.service.ICmsTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("template")
public class CmsTemplateController implements CmsTemplateControllerApi {

    @Autowired
    ICmsTemplateService cmsTemplateService;


    @Override
    @GetMapping("findTemplate")
    public QueryResponseResult findTemplate(String siteId, String templateName) {

        QueryResult<CmsTemplate> queryResult = new QueryResult<>();
        List<CmsTemplate> template = cmsTemplateService.findTemplate(siteId, templateName);

        queryResult.setList(template);
        queryResult.setTotal(template.size());

        QueryResponseResult queryResponseResult = new QueryResponseResult(CommonCode.SUCCESS,queryResult);
        return queryResponseResult;
    }

    @Override
    @PostMapping("addTemplate")
    public void addTemplate(CmsTemplate cmsTemplate) {
        cmsTemplateService.addTemplate(cmsTemplate);
    }
}
